
#pragma once

#include "zen_vap.h"
#include "MyConfig.h"

using namespace Zen;
using namespace Zen::Vap;

class RootScene3d : public Combination2D {
	Random ra;
public:
	RootScene3d()
	{
	}

	void load() override
	{
		auto cube = MeshLoader::Get()->createMeshCubeSameface();
		MeshesCache::Get()->cacheMesh("cube", cube);

		MeshesCache::Get()->cacheMesh("skybox", MeshLoader::Get()->createMeshCubeSkybox());

		MeshesCache::Get()->cacheMesh("skybox1",  MeshLoader::Get()->createMeshCubeSkybox(0.5f, 1));

		this->SkyBox();

		int n = 2;
		float m = 20.f / (n+1);
		for(int j = -n; j <= n; ++j)
			for(int i = -n; i <= n; ++i)
				AddEntity(Vec3{m*i, m*j, -20.f});

	}
	Entity * SkyBox()
	{
		auto en = std::make_shared<Entity>();
		this->addNode(en);

		en->ro = 0.1f;
		en->setMesh(MeshesCache::Get()->getMesh("skybox1"));
		en->setTexture(TexturesCache::Get()->getTexture("res/sky1.jpg"));
		en->setRotationAxis({ 0, 1, 0 });
		en->ro = 0.003f;
		en->setScale({20, 20, 20});
		en->setCullFace(eFace::Front);
		return en.get();
	}

	Entity * AddEntity(Vec3 move)
	{
		auto en = std::make_shared<Entity>();
		this->addNode(en);

		en->setPosition(move*0.2f);

		en->setScale({0.5, 0.5, 0.5});
		en->ro =  ra.nextf() * 0.02f;
		en->setRotationAxis({ ra.nextf(), ra.nextf(), ra.nextf() });
		en->setMesh(MeshesCache::Get()->getMesh("cube"));
		en->setTexture(TexturesCache::Get()->getTexture("res/s.jpg"));
		en->setCullFace(eFace::None);
		return en.get();
	}
};
